<template>
  <div style="padding: 6px;">
    <el-table :data="tbworkObj.list" border style="width: 100%">
      <el-table-column label="任务编号" prop="id"></el-table-column>
      <el-table-column label="任务名称" prop="title"></el-table-column>
      <el-table-column label="任务频率" prop="pinlv"></el-table-column>
      <el-table-column label="最后同步时间">
        <template v-slot="scope">
          <DateFormat :value="scope.row.updatetime" :format="'YYYY-MM-DD HH:mm'"></DateFormat>
        </template>
      </el-table-column>
      <el-table-column label="状态" width="80px">
        <template v-slot="scope">
          <el-switch v-model="scope.row.statusid" :active-value="1" :inactive-value="0" @change="changeRowStatusid($event,scope.row)" active-color="#13ce66" ></el-switch>
        </template>
      </el-table-column>
      <el-table-column label="#" width="150px">
        <template v-slot="scope">
          <el-button size="mini" type="primary" @click="viewLog(scope.row.id)">查看日志</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination class="center" background layout="total, prev, pager, next"
                   @current-change="loadTbWork" :total="tbworkObj.total"
                   :current-page.sync="sd.pageNum" :page-size="sd.pageSize">
    </el-pagination>
    <el-drawer title="同步日志查看" :visible.sync="logViewVisible" direction="rtl" :wrapperClosable="true" size="60%">
      <tbworklog v-if="logViewVisible" :visible.sync="logViewVisible" :workId="workId"></tbworklog>
    </el-drawer>
  </div>
</template>

<script>
import request from '@/utils/request'
import tbworklog from "@/views/tbwork/tbworklog";
export default {
  components : {tbworklog},
  data() {
    return {
      sd: {
        pageNum: 1,
        pageSize: 15
      },
      tbworkObj: {},
      logViewVisible : false,
      workId: 0,
    }
  },
  mounted() {
    this.loadTbWork()
  },
  methods: {
    viewLog(id){
      this.workId= id;
      this.logViewVisible = true
    },
    changeRowStatusid(event, data){
      request({
        url: '/tbwork/updateworklogstatusid',
        data: {workId : data.id, statusId : data.statusid}
      })
    },
    loadTbWork() {
      request({
        url: '/tbwork/pagetbwork',
        data: this.sd
      }).then(res => {
        const { data } = res
        this.tbworkObj = data
      })
    },
  }
}
</script>
